﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class ordersTypeList : System.Web.UI.Page
    {
        public int pid
        {
            get
            {
                return int.Parse(ViewState["pid"].ToString());
            }
            set
            {
                ViewState["pid"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string tablename = "Shop";
            this.ddlShop.DataSource = new ShopBLL().Select(tablename);
            this.ddlShop.DataValueField = "ID";
            this.ddlShop.DataTextField = "Name";
            this.ddlShop.DataBind();
            string name = "Orders";
            this.ddlOrdersID.DataSource = new OrdersBLL().Select(name);
            this.ddlOrdersID.DataValueField = "ID";
            this.ddlOrdersID.DataTextField = "ID";
            this.ddlOrdersID.DataBind();
            if (!IsPostBack)
            {
                pid = 0;
                if (Request["id"] != null)
                {
                    string TableName = "OrdersType";
                    pid = int.Parse(Request["ID"].ToString());
                    OrdersTypeModel model = new OrdersTypeBLL().GetModelByID(TableName, pid);
                    //this.txtOrdersID.Value = model.OrdersID.ToString();
                    //this.txtShopID.Value = model.ShopID.ToString();
                    this.txtNo.Value = model.No.ToString();
                    this.txtPrice.Value = model.Price.ToString();
                    this.txtRemark.Value = model.Remark;
                }

            }
        }

        protected void btnSave_click(object sender, EventArgs e)
        {
            OrdersTypeModel model = new OrdersTypeModel()
            {

                OrdersID = int.Parse(this.ddlOrdersID.SelectedValue),
                ShopID = int.Parse(this.ddlShop.SelectedValue),
                Price=decimal.Parse(this.txtPrice.Value),
                No = int.Parse(this.txtNo.Value),
                Remark = this.txtRemark.Value,

            };
            OrdersTypeBLL bll = new OrdersTypeBLL();
            if (pid > 0)
            {
                bll.Gai(model, pid);

            }
            else
            {
                bll.Add(model);


            }
            Response.Redirect("ordersType.aspx");
        }
    }
}